//
//  FrontViewController.m
//  SalonManage
//
//  Created by tim on 2017/7/20.
//  Copyright © 2017年 lmtt. All rights reserved.
//

#import "FrontViewController.h"
#import "ImgBrowseController.h"
#import "OpenOrderController.h"
#import "LoginViewController.h"
#import "SiginViewController.h"


@interface FrontViewController ()
@property (nonatomic,strong)UILabel * timeLabel;
@property (nonatomic,strong)LMButton * priceBtn;
@property (nonatomic,strong)LMButton * openOrderBtn;
@property (nonatomic,strong)LMButton * loginBtn;
@property (nonatomic,strong)LMButton * registerBtn;

@end

@implementation FrontViewController
-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitle:@"卡方电子化录单系统"];
    [self.view setBackgroundColor:[UIColor whiteColor]];
     [self createMainView];
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        NSLog(@"iPad\n");
    } else {
        NSLog(@"iPhone\n");
    }
}


-(void)createMainView{
    [self.view addSubview:self.timeLabel];
    
    [self.view addSubview:self.priceBtn];
    [self.view addSubview:self.openOrderBtn];
    [self.view addSubview:self.loginBtn];
    [self.view addSubview:self.registerBtn];
    NSLog(@"__kScreenWidth-----%f",__kScreenWidth);
    
    [self setHorizontalFrame];

}

- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    
    //注册屏幕旋转 消息通知
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(changeFrames:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];

}

//收到通知后改变view坐标

-(void)changeFrames:(NSNotification *)notification{
    

    if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait
        
        || [[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortraitUpsideDown){
        NSLog(@"portrait");
        
        [self setVerticalFrame];
    }else{
        NSLog(@"横屏");
        [self setHorizontalFrame];
    }
}

-(void)setVerticalFrame
{
    NSLog(@"竖屏");
    self.timeLabel.whc_TopSpace(64).whc_LeftSpace(0).whc_RightSpace(0).whc_Height(100*ADPT);
    self.priceBtn.whc_TopSpaceToView( 150*ADPT, self.timeLabel).whc_LeftSpace(HGADPT(60)).whc_Height(HGADPT(100)).whc_Width(__kScreenWidth/2-HGADPT(160));
    self.openOrderBtn.whc_CenterYToView(0, self.priceBtn).whc_SizeEqualView(self.priceBtn).whc_RightSpace(HGADPT(60));
    self.loginBtn.whc_TopSpaceToView(HGADPT(80), self.priceBtn).whc_CenterXToView(0, self.priceBtn).whc_SizeEqualView(self.priceBtn);
    
    self.registerBtn.whc_TopSpaceToView(HGADPT(80), self.priceBtn).whc_CenterXToView(0, self.openOrderBtn).whc_SizeEqualView(self.priceBtn);

}

-(void)setHorizontalFrame
{
    NSLog(@"横屏");
    self.timeLabel.whc_TopSpace(64).whc_LeftSpace(0).whc_RightSpace(0).whc_Height(100*ADPT);
    self.priceBtn.whc_TopSpaceToView( 100*ADPT, self.timeLabel).whc_LeftSpace(HGADPT(120)).whc_Height(HGADPT(100)).whc_Width(__kScreenWidth/2-HGADPT(160));
    self.openOrderBtn.whc_CenterYToView(0, self.priceBtn).whc_SizeEqualView(self.priceBtn).whc_RightSpace(HGADPT(120));
    self.loginBtn.whc_TopSpaceToView(HGADPT(80), self.priceBtn).whc_CenterXToView(0, self.priceBtn).whc_SizeEqualView(self.priceBtn);
    
    self.registerBtn.whc_TopSpaceToView(HGADPT(80), self.priceBtn).whc_CenterXToView(0, self.openOrderBtn).whc_SizeEqualView(self.priceBtn);
  
}

-(UILabel *)timeLabel{
    if (_timeLabel == nil) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.backgroundColor = [UIColor blackColor];
        NSDate *currentDate = [NSDate date];//获取当前时间，日期
        _timeLabel.text = [NSString stringWithFormat:@"日期： %@  %@",[BaseViewController stringFromDate:currentDate],[BaseViewController weekdayStringFromDate:currentDate]];
//        @"日期： 2017-7-12 10：30 星期日";
        _timeLabel.textAlignment = NSTextAlignmentCenter;
        _timeLabel.backgroundColor = [UIColor whiteColor];
        _timeLabel.font = _kFont32;
    }
    return _timeLabel;
}

-(LMButton *)priceBtn{
    if (_priceBtn ==nil) {
        _priceBtn = [LMButton lm_buttonWithType:LMButtonTypeMove title:@"价格单"];
        kWeakSelf(self)
        _priceBtn.onClick = ^(LMButton *btn) {
            ImgBrowseController * imgVC =[[ImgBrowseController alloc]init];
            [weakself.navigationController pushViewController:imgVC animated:YES];
            
        };
        
    }
    return _priceBtn;
}

-(LMButton *)openOrderBtn{
    if (_openOrderBtn == nil) {
        _openOrderBtn = [LMButton lm_buttonWithType:LMButtonTypeMove title:@"开单"];
        kWeakSelf(self)
        _openOrderBtn.onClick = ^(LMButton *btn) {
            OpenOrderController * next =[[OpenOrderController alloc]init];
            [weakself.navigationController pushViewController:next animated:YES];
            
        };
    }
    return _openOrderBtn;
}

-(LMButton *)loginBtn{
    if (_loginBtn == nil) {
        _loginBtn = [LMButton lm_buttonWithType:LMButtonTypeMove title:@"登录"];
        kWeakSelf(self)
        _loginBtn.onClick = ^(LMButton *btn) {
            LoginViewController * next =[[LoginViewController alloc]init];
            [weakself.navigationController pushViewController:next animated:YES];
            
        };

    }
    return _loginBtn;
}

-(LMButton *)registerBtn{
    if (_registerBtn == nil) {
        _registerBtn = [LMButton lm_buttonWithType:LMButtonTypeMove title:@"注册"];
        kWeakSelf(self)
        _registerBtn.onClick = ^(LMButton *btn) {
            SiginViewController * next =[[SiginViewController alloc]init];
            [weakself.navigationController pushViewController:next animated:YES];
            
        };
    }
    return _registerBtn;
}
@end
